#include<iostream>
#include <algorithm>
#include<cstring>
#include<string>

using namespace std;


const int N = 110;
int n;
int g[N][N];
bool v[N][N]; //是否访问

void graphc(int n, string x){
    for (int i = 0; i < x.length(); i ++){
        int c = x[i] - '0';
        g[n][i + 1] = c;
    }
}



int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);

    int T;
    string x;
    cin >> T;
    // (x, y) -->90 (y, n - x + 1) -->90 (n - x + 1, n - y + 1) -->90 (n - y + 1, x)
    while(T--){
        memset(v, 0, sizeof v);
        cin >> n;

        for (int i = 1; i <= n; i ++){
            cin >> x;
            graphc(i, x);
        }

        int sum = 0;
        for (int i = 1; i <= n; i ++){
            for (int j = 1; j <= n; j ++){
                if(v[i][j]){
                    continue;
                }
                v[i][j] = v[j][n - i + 1] = v[n - i + 1][n - j + 1] = v[n - j + 1][i] = true;
                int mv1 = (g[i][j] == 0) + (g[j][n - i + 1] == 0) + (g[n - i + 1][n - j + 1] == 0) + (g[n - j + 1][i] == 0);
                int mv2 = (g[i][j] == 1) + (g[j][n - i + 1] == 1) + (g[n - i + 1][n - j + 1] == 1) + (g[n - j + 1][i] == 1);
                sum += min(mv1, mv2);
            }
        }

           cout << sum << endl;
    }

    return 0;
}